﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebsiteDataModel;

public partial class morning_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }

            showList(page);
        }
    }

    protected void showList(int page)
    {
        WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
        string name = Request["name"];
        string stock = Request["stock"];
        string sortType = Request["sortType"];
        var list = de.XG_Detail.AsQueryable();
        if (!string.IsNullOrEmpty(name))
        {
            list=list.Where(x => x.gpjc.Contains(name));
        }
        if (!string.IsNullOrEmpty(stock))
        {
            list = list.Where(x => x.gpdm.Contains(stock));
        }
        if (!string.IsNullOrEmpty(sortType))
        {
            if (sortType == "0")
            {
                list = list.OrderByDescending(x => x.ssrq);
            }
            else
            {
                list = list.OrderByDescending(x => x.fxrq);
            }
        }
        else
        {
            list = list.OrderByDescending(a => a.zqhggr);
        }
        //list = de.XG_Detail.Where(x => x.ssrq > edate).Select(a => new { a.id, a.gpdm, a.gpjc, a.sgdm, a.zfxgs, a.fxgs, a.sgsl, a.fxjg, a.fxrq, a.zqhggr, a.ssrq, a.fxsyl, a.fxzql });
        AspNetPager1.RecordCount = list.Count();
        list = list.Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);

        Repeater1.DataSource = list;
        Repeater1.DataBind();
    }

    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        showList(AspNetPager1.CurrentPageIndex);
    }
}